using System;
using System.Collections.Generic;

namespace SmartSite.Frame
{
    public class IntField : LongField, IValueField<int>
    {
        const int MaxCount = 32;
        public IntField(List<byte> buffer, BitUnit index, BitUnit count)
        : base(buffer, index, count)
        { CheckingOutOfRange(count, nameof(count)); }

        public IntField(IBytesBuffer buffer, BitUnit index, BitUnit count)
        : base(buffer, index, count)
        { CheckingOutOfRange(count, nameof(count)); }

        public IntField(IField field, BitUnit count)
        : base(field, count)
        { CheckingOutOfRange(count, nameof(count)); }

        public IntField(IField field)
        : base(field, MaxCount) { }


        static BitUnit CheckingOutOfRange(BitUnit count, string name)
        {
            if (count > MaxCount || count < 0)
                throw new ArgumentOutOfRangeException(name);

            return count;
        }


        public new int Value
        {
            get => (int)base.Value;
            set => base.Value = value;
        }
    }
}